package com.bjsxt.set;

import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;

public class TestSet {

    public static void main(String[] args) {

        //HashSet集合的特点：无序、不重复、无索引
        //LinkedHashSet集合的特点：有序（添加顺序）、不重复、无索引
        Set<String> set = new HashSet<>();
        //Set<String> set = new LinkedHashSet<>();
        set.add("hello");
        set.add("world");
        set.add("HTML");
        set.add("java");
        set.add("hello");
        set.add("Python");
        set.add("Go");
        System.out.println(set.size());
        System.out.println(set);

        System.out.println("==============================");

        //遍历
        for (String s : set) {
            System.out.println(s);
        }

        System.out.println("==============================");

        //迭代器
        Iterator<String> it = set.iterator();
        while(it.hasNext()) {
            String s = it.next();
            System.out.println(s);
        }
    }
}
